﻿using System;
using System.IO.Ports;
using System.Windows.Forms;
using MyTech.DataAccess.Common;

namespace MySqlNSerial
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Test
                using(var dbInstance = new QueryExecutorMultiDb())
                {
                    dbInstance.DbInstanceType = DbObjectType.MsSQL | DbObjectType.MySQL;
                    dbInstance.Load(); 
                                       
                    //string sqlText = "SELECT * FROM dm;";
                    var sqlText = "test_proc";
                    var data = dbInstance.ExecuteReader(sqlText, DbObjectType.MySQL);


                    //var sqlUpdate = "UPDATE dm SET USERNAMENAME='UpdatedName' WHERE RowID = 1";
                    //int? count = dbInstance.ExecuteNonQuery(sqlUpdate, DbObjectType.MySQL);
                }             

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
            
        }

        //private void button2_Click(object sender, EventArgs e)
        //{
        //   SerialPort _serialPort = null;
        //    try
        //    {

        //        var port = new SerialPort("COM12", 19200, Parity.None, 8, StopBits.One);
        //        port.Open();

        //        port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

        //       _serialPort = new SerialPort("COM10", 19200, Parity.None, 8, StopBits.One);
        //        _serialPort.Handshake = Handshake.None;
        //        if (!(_serialPort.IsOpen))
        //            _serialPort.Open();

        //        _serialPort.Write("Hello Serial port.");
                
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.StackTrace);
        //    }
        //    finally
        //    {
        //        if (null != _serialPort)
        //        {
        //            _serialPort.Close();
        //            _serialPort.Dispose();
        //            _serialPort = null;                    
        //        }
        //    }
        //}

        //void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        //{
        //    var port = sender as SerialPort;

        //    Console.WriteLine(port.ReadExisting());
        //}
    }
}
